﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>调度任务管理</title>
    <meta name="description" content="">
    <meta name="author" content="">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <!-- #CSS Links -->
    <!-- Basic Styles -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/font-awesome.css">

    <!-- SmartAdmin Styles : Caution! DO NOT change the order -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production-plugins.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-skins.css">

    <!-- SmartAdmin RTL Support -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-rtl.css">

    <!-- Demo purpose only: goes with demo.js, you can delete this css when designing your own WebApp -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/demo.css">

    <!-- #FAVICONS -->
    <link rel="shortcut icon" href="img/favicon/favicon.ico" type="image/x-icon">
    <link rel="icon" href="img/favicon/favicon.ico" type="image/x-icon">

    <!-- #GOOGLE FONT -->
    <link rel="stylesheet" href="css/open-sans.css" type="text/css">

    <!-- #APP SCREEN / ICONS -->
    <link rel="apple-touch-icon" href="img/splash/sptouch-icon-iphone.png">
    <link rel="apple-touch-icon" sizes="76x76" href="img/splash/touch-icon-ipad.png">
    <link rel="apple-touch-icon" sizes="120x120" href="img/splash/touch-icon-iphone-retina.png">
    <link rel="apple-touch-icon" sizes="152x152" href="img/splash/touch-icon-ipad-retina.png">

    <!-- iOS web-app metas : hides Safari UI Components and Changes Status Bar Appearance -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <!-- Startup image for web apps -->
    <link rel="apple-touch-startup-image" href="img/splash/ipad-landscape.png"
          media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)">
    <link rel="apple-touch-startup-image" href="img/splash/ipad-portrait.png"
          media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)">
    <link rel="apple-touch-startup-image" href="img/splash/iphone.png" media="screen and (max-device-width: 320px)">
    <link href="appcss/Common.css" rel="stylesheet" />

    <style>
        .dt-toolbar div .dataTables_filter {
            width: auto !important;
        }
    </style>
</head>
<body class="desktop-detected minified">

    <!-- #MAIN PANEL -->
    <div id="main" role="main">

        <!-- RIBBON -->
        <div id="ribbon">

            <span class="ribbon-button-alignment">
                <span class="btn btn-ribbon"><i class="fa fa-home"></i></span>
            </span>

            <!-- breadcrumb -->
            <ol class="breadcrumb">
                <li>调度任务管理</li>
            </ol>
            <!-- end breadcrumb -->

        </div>
        <!-- END RIBBON -->
        <!-- MAIN CONTENT -->
        <div id="content">
            <div class="row hidden">
                <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                    <h2 class="page-title txt-color-blueDark">
                        <i class="fa fa-table fa-fw "></i>
                        主页

                        <span>
                            调度任务管理
                        </span>
                    </h2>
                </div>
            </div>

            <!-- widget grid -->
            <section id="widget-grid" class="">

                <!-- row -->
                <div class="row" style="margin-top: 8px;">
                    <!-- NEW WIDGET START -->
                    <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">

                        <!-- Widget ID (each widget will need unique ID)-->
                        <div class="jarviswidget jarviswidget-sortable" id="wid-id-0"
                             data-widget-editbutton="false">
                            <header>
                                <span class="widget-icon"><i class="fa fa-table"></i></span>

                                <h2>调度任务列表</h2>

                            </header>

                            <!-- widget div-->
                            <div>

                                <!-- widget edit box -->
                                <div class="jarviswidget-editbox">
                                    <!-- This area used as dropdown edit box -->

                                </div>
                                <!-- end widget edit box -->
                                <!-- widget content -->
                                <div class="widget-body">
                                    <ul class="demo-btns">
                                        <li>
                                            板块
                                            <select id="ctlListTaskCategory">
                                                <option value="">全部</option>
                                            </select>
                                        </li>
                                        <li>
                                            系统
                                            <select id="ctlListSubTaskCategory">
                                                <option value="">全部</option>
                                            </select>
                                        </li>
                                        <li>
                                            <input type="text" style="width: 300px;" placeholder="请输入任务名称" id="Filter" name="Filter">
                                        </li>
                                        <li>
                                            <a class="btn  btn-default btn-xs" href="javascript:table.fnDraw();">刷新列表 </a>
                                        </li>
                                        <li>
                                            <a class="btn  btn-default btn-xs" href="SchedulingTaskCreateOne.html">新增 </a>
                                        </li>
                                        <li>
                                            <a class="btn  btn-default btn-xs" href="SchedulingTaskRegisterEBS.html">注册到EBS </a>
                                        </li>

                                    </ul>
                                    <div class="table-responsive">

                                        <table class="table table-bordered table-hover smart-form" id="datalist-table">
                                            <thead>
                                            <tr>
                                                <th>系统</th>
                                                <th>任务名称</th>
                                                <th>数据源</th>
                                                <th>状态</th>
                                                <th>上次调度时间</th>
                                                <th>模式</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody></tbody>
                                        </table>

                                    </div>

                                </div>
                                <!-- end widget content -->

                            </div>
                            <!-- end widget div -->

                        </div>

                        <!-- end widget -->

                    </article>
                    <!-- WIDGET END -->

                </div>

                <!-- end row -->

            </section>
            <!-- end widget grid -->
        </div>
        <!-- END MAIN CONTENT -->
    </div>

    <!-- END #MAIN CONTENT -->
    <!--================================================== -->
    <!-- PACE LOADER - turn this on if you want ajax loading to show (caution: uses lots of memory on iDevices)
    <script data-pace-options='{ "restartOnRequestAfter": true }' src="js/plugin/pace/pace.min.js"></script>-->
    <!-- #PLUGINS -->
    <!-- Link to Google CDN's jQuery + jQueryUI; fall back to local -->


    <script src="js/libs/jquery-2.1.1.min.js"></script>
    <script src="js/libs/jquery-ui-1.10.3.min.js"></script>
    <!-- BOOTSTRAP JS -->
    <script src="js/bootstrap/bootstrap.min.js"></script>

    <!-- IMPORTANT: APP CONFIG -->
    <script src="js/app.config.js"></script>


    <!-- CUSTOM NOTIFICATION -->
    <script src="js/notification/SmartNotification.min.js"></script>

    <!-- JARVIS WIDGETS -->
    <script src="js/smartwidgets/jarvis.widget.min.js"></script>


    <!-- SPARKLINES -->
    <script src="js/plugin/sparkline/jquery.sparkline.min.js"></script>

    <!-- JQUERY MASKED INPUT -->
    <script src="js/plugin/masked-input/jquery.maskedinput.min.js"></script>


    <!-- JQUERY UI + Bootstrap Slider -->
    <script src="js/plugin/bootstrap-slider/bootstrap-slider.min.js"></script>


    <!--[if IE 8]>
    <h1>Your browser is out of date, please update your browser by going to www.microsoft.com/download</h1>
    <![endif]-->
    <!-- Demo purpose only
    <script src="js/demo.min.js"></script>
    -->
    <!-- MAIN APP JS FILE -->
    <script src="js/plugin/datatables/jquery.dataTables.min.js"></script>
    <script src="js/plugin/datatables/dataTables.colVis.min.js"></script>
    <script src="js/plugin/datatables/dataTables.tableTools.min.js"></script>
    <script src="js/plugin/datatables/dataTables.bootstrap.min.js"></script>
    <script src="js/plugin/datatable-responsive/datatables.responsive.min.js"></script>
    <script src="appjs/Common.js"></script>
    <script src="appjs/Helper.js"></script>
    <script>
        var draw = 0;
        var serviceId = GetQueryString("Id");
        $(function () {
            //初始化表格
            var initializationDataTable = function () {
                this.table = $('#datalist-table').dataTable({
                    "autoWidth": true,
                    "oLanguage": dataTableConfig,
                    "bLengthChange": false,
                    ordering: false,
                    bProcessing: true,
                    bStateSave: true,
                    serverSide: true,
                    searching: false,
                    aLengthMenu: [25],
                    "ajax": {
                        url: apiUrl,
                        "dataSrc": function (json) {
                            if (json.IsSccuess) {
                                var newjson = new Array();
                                for (var i = 0; i < json.Data.Items.length; i++) {
                                    var editstr = "";
                                    editstr += ("<a href=\"SchedulingTaskDataMonitoringExampleManagement.html?taskId=" + json.Data.Items[i].Id + "\"><i class=\"fa fa-hand-o-right\"></i>数据监控实例</a>&nbsp;");
                                    editstr += ("<a href='javascript:void(0);' onclick='TaskExecution(this," + json.Data.Items[i].RunMode + ")' data=\"SchedulingTaskManualExecutionOne.html?taskId=" + json.Data.Items[i].Id + "\"><i class=\"fa fa-hand-o-right\"></i>执行</a>&nbsp;");
                                    editstr += "<a href=\"SchedulingTaskManualExecutionTwo.html?taskId=" + json.Data.Items[i].Id;
                                    editstr += "\"><i class=\"fa   fa-arrow-circle-right\"></i>数据审核</a>";
                                    editstr += ("<a  href=\"SchedulingTaskExecutionRecord.html?taskId=" + json.Data.Items[i].Id + "\"><i  class=\"fa fa-users\"></i>查看</a>");
                                    editstr += ("<a href=\"javascript:void(0);\" onclick=\"EnableOrDisableTask(this)\" data-Id=\"" + json.Data.Items[i].Id + "\" data='" + json.Data.Items[i].IsEnabled + "'><i class=\"fa   " + (json.Data.Items[i].IsEnabled ? "fa-circle" : "fa-dot-circle-o ") + "\"></i>");
                                    editstr += ((json.Data.Items[i].IsEnabled ? "禁用" : "启用") + "</a>");
                                    editstr += "<a href=\"javascript:void(0);\" onclick='DeleteTask(this)' data-Id=\"" + json.Data.Items[i].Id;
                                    editstr += "\"><i class=\"fa  fa-times-circle\"></i>删除</a>";

                                    var lookstr = "<a href=\"SchedulingTaskExecutionRecord.html?taskId=" + json.Data.Items[i].Id;
                                    lookstr += "\">" + json.Data.Items[i].Name + "</a>";
                                    newjson.push({ categoryname: json.Data.Items[i].CategoryName, "name": lookstr, "dataSource": json.Data.Items[i].DtSourceText, "state": (json.Data.Items[i].IsEnabled ? "启用" : "禁用"), "lastTime": json.Data.Items[i].LastExecutedTime, "mode": GetRunModeName(json.Data.Items[i].RunMode), "option": editstr });
                                }
                                return newjson;
                            } else {
                                if (IsLogined(json.ErrorCode)) {
                                    alert("失败（" + "错误代码：" + json.ErrorCode + "，错误信息：" + json.Message + ")");
                                }
                            }
                            return [];
                        },
                        "data": function (d) {
                            draw = d.draw;
                            return $.extend({}, { "sys:sno": "ETL" }, { "sys:act": "GetTaskList" }, { "draw": d.draw }, { "length": d.length }, { "Page": parseInt(d.start / d.length) }, { "Filter": $("#Filter").val() }, { "CategoryId": $('#ctlListSubTaskCategory').val() });
                        }
                    },
                    columns: [
                        { data: 'categoryname' },
                        { data: 'name' },
                        { data: 'dataSource' },
                        { data: 'state' },
                        { data: 'lastTime' },
                        { data: 'mode' },
                        { data: 'option' }

                    ]
                });
            }

            listTaskCategory();
            initializationDataTable();

            $('#ctlListTaskCategory').on('change', function () {
                listSubTaskCategory();
            });
        });
        var EnableOrDisableTask = function (obj) {
            var $this = $(obj);
            var state = $this.attr("data");
            var id = $this.attr("data-Id");
            var str = "";
            var act = "";
            var successstr = "";
            if (state == "true") {
                str = "禁用";
                act = "Disable";
            } else {
                str = "启用";
                act = "Enable";
            }
            if (confirm("确定" + str + "该任务？")) {
                $.ajax({
                    url: apiUrl,
                    data: {
                        "sys:sno": "TASK",
                        "sys:act": act,
                        "TaskId": id
                    },
                    type: "Post",
                    dataType: "json",
                    success: function (data) {
                        if (data.IsSccuess) {
                            ShowGritter(str + "成功", 2);
                        } else {
                            if (IsLogined(data.ErrorCode)) {
                                alert("错误代码：" + data.ErrorCode + "，错误信息：" + data.Message);
                            }
                        }
                    },
                    beforeSend: function () {
                        ShowGritter("提交中");
                    },
                    error: function () {
                        alert("系统异常，请稍后重试");
                    }
                });
            }
        }
        var DeleteTask = function (obj) {
            var $this = $(obj);
            var id = $this.attr("data-Id");

            if (confirm("确定删除该项？")) {
                $.ajax({
                    url: apiUrl,
                    data: {
                        "sys:sno": "TASK",
                        "sys:act": "Delete",
                        "TaskId": id
                    },
                    type: "Post",
                    dataType: "json",
                    success: function (data) {
                        if (data.IsSccuess) {
                            //ShowGritter("删除成功", 2);
                            ShowGritter("删除成功");
                            $this.parent().parent().remove();
                        } else {
                            if (IsLogined(data.ErrorCode)) {
                                alert("错误代码：" + data.ErrorCode + "，错误信息：" + data.Message);
                            }
                        }
                    },
                    beforeSend: function () {
                        ShowGritter("提交中");
                    },
                    error: function () {
                        alert("系统异常，请稍后重试");
                    }
                });
            }
        }
        //获取运行模式
        var GetRunModeName = function (id) {
            var str = "";
            switch (id) {
                case 1:
                    str = "定时器";
                    break;
                case 2:
                    str = "闹钟";
                    break;
                case 3:
                    str = "手动";
                    break;
                case 4:
                    str = "事件";
                    break;
            }
            return str;
        }
        var TaskExecution = function (obj, id) {
            var $this = $(obj);
            if (id != 3) {
                var str = "当前任务的执行模式是：" + GetRunModeName(id) + ",非手动模式，确定手动执行？";
                if (confirm(str)) {
                    window.location.href = $this.attr("data");
                }
            } else {
                window.location.href = $this.attr("data");
            }
        }

        function listTaskCategory() {
            $.ajax({
                url: g_webApiBaseUrl + 'List/RootTaskCategory',
                type: "Get",
                dataType: "json",
                async: false,
                data: {},
                success: function (data) {
                    if (data.IsSuccess) {
                        if (data.Data != null && data.Data.length != 0) {
                            for (var index = 0; index < data.Data.length; index++) {
                                $('#ctlListTaskCategory').append('<option value="' + data.Data[index].Id + '">' + data.Data[index].Name + '</option>');
                            }
                        }
                    } else {
                        if (IsLogined(data.ErrorCode)) {
                            alert("错误代码：" + data.ErrorCode + "，错误信息：" + data.Message);
                        }
                    }
                },
                error: function () {
                    alert("系统异常，请稍后重试");
                }
            });
        }

        function listSubTaskCategory() {
            var parentId = $('#ctlListTaskCategory').val();
            if (!parentId) {
                $('#ctlListSubTaskCategory option').remove();
                $('#ctlListSubTaskCategory').append('<option value="">全部</option>');
                return;
            }
            $('#ctlListSubTaskCategory option').remove();
            $.ajax({
                url: g_webApiBaseUrl + 'List/SubTaskCategory',
                type: "Get",
                dataType: "json",
                async: false,
                data: { 'parentId': parentId },
                success: function (data) {
                    if (data.IsSuccess) {
                        if (data.Data != null && data.Data.length != 0) {
                            for (var index = 0; index < data.Data.length; index++) {
                                $('#ctlListSubTaskCategory').append('<option value="' + data.Data[index].Id + '">' + data.Data[index].Name + '</option>');
                            }
                        }
                    } else {
                        if (IsLogined(data.ErrorCode)) {
                            alert("错误代码：" + data.ErrorCode + "，错误信息：" + data.Message);
                        }
                    }
                },
                error: function () {
                    alert("系统异常，请稍后重试");
                }
            });
        }
    </script>


</body>
</html>

